import Vue from "vue";
import Vuex from "vuex";

import storeAuth from "./modules/auth";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    stations: [],
  },
  mutations: {
    SET_STATIONS(state, stations) {
      state.stations = stations || [];
    },
  },
  actions: {
    /**
     * [{ id: 1, name: "长沙南站" }]
     */
    updateStations({ commit }, stations) {
      commit(
        "SET_STATIONS",
        stations.sort((a, b) =>
          a.pinyin < b.pinyin ? -1 : a.pinyin > b.pinyin ? 1 : 0
        )
      );
    },
  },
  modules: {
    auth: storeAuth,
  },
});

export default store;
